package io.renren.modules.common.service.impl;

import io.renren.modules.common.viewdo.SelectOption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.common.dao.CertificateDao;
import io.renren.modules.common.entity.CertificateEntity;
import io.renren.modules.common.service.CertificateService;


@Service("certificateService")
public class CertificateServiceImpl extends ServiceImpl<CertificateDao, CertificateEntity> implements CertificateService {

    @Autowired
    private CertificateDao certificateDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CertificateEntity> page = this.page(
                new Query<CertificateEntity>().getPage(params),
                new QueryWrapper<CertificateEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<SelectOption> selectOptionCertificate() {

        List<CertificateEntity> certificateEntities = certificateDao.selectList(null);
        List<SelectOption> collect = certificateEntities.stream().map(item -> new SelectOption(item.getId().toString(), item.getCertificateName())).collect(Collectors.toList());
        return collect;
    }

}